package wowraidmanager.server.service.wishlist.contact;

import java.io.IOException;

import wowraidmanager.client.service.wishlist.contact.ContactService;
import wowraidmanager.shared.model.wishlist.Member;

import com.google.appengine.api.mail.MailService;
import com.google.appengine.api.mail.MailService.Message;
import com.google.appengine.api.mail.MailServiceFactory;

public class ContactServiceImpl implements ContactService{

    MailService mailService = MailServiceFactory.getMailService();
    Message message = new Message();
    static String ADMIN_EMAIL = "tlubtlub@gmail.com";

    public void sendMail(String title, String content, Member member) throws IOException{
        if(title == null || title.length() == 0){
            title = "無題";
        }

        title += " by " + member.getMemberName();

        message.setSender(ADMIN_EMAIL);
        message.setSubject(title);
        message.setHtmlBody(content);

        mailService.sendToAdmins(message);

    }

    public void sendContactCheckMail(String title, String content, Member member) throws IOException{
        if(title == null || title.length() == 0){
            title = "無題";
        }

        message.setSender(ADMIN_EMAIL);
        message.setTo(member.getMemberAccount());
        message.setSubject(title + "の送信確認(自動送信)");
        message.setHtmlBody("以下の内容を管理者に送信しました。<br/><br/>" + content);

        mailService.send(message);
    }

    public void sendRegistToAdmin(String guildNameString, String realmNameString, String memberNameString, String memberAccountString)throws IOException{

        String htmlBody = "GuildName:" + guildNameString + "<br/>" +
                            "RealmName:" + realmNameString + "<br/>" +
                            "代表者名:" + memberNameString + "<br/>" +
                            "代表者のGoogleアカウント:" + memberAccountString;
        message.setSender(ADMIN_EMAIL);
        message.setSubject("Wishlist新規登録について");
        message.setHtmlBody(htmlBody);

        mailService.sendToAdmins(message);
    }

    public void sendCronMail(String title, String content) throws IOException{
        message.setSender(ADMIN_EMAIL);
        message.setSubject(title);
        message.setHtmlBody(content);

        mailService.sendToAdmins(message);
    }
}
